﻿using System;
using System.Configuration;
using System.Linq;
using Controllers;

namespace Web
{
    public partial class ExamTypeList : System.Web.UI.Page
    {
        protected Pagination Model;
        protected string noDisplay = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Model = new Pagination();
            Model.PageNumShown = 6;
            Model.CurrentPage = 1;
            Model.NumPerPage = 10;
            //EmpBasicInfo ebi = Session["ebi"] as EmpBasicInfo;
            if (Request.QueryString["pageNum"] != null)
            {
                Model.CurrentPage = int.Parse(Request.QueryString["pageNum"]);
            }
            if (Request.QueryString["numPerPage"] != null)
            {
                Model.NumPerPage = int.Parse(Request.QueryString["numPerPage"]);
            }
            ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            int sNum = (Model.CurrentPage - 1) * Model.NumPerPage + 1;
            int eNum = Model.CurrentPage * Model.NumPerPage;
            string strSql = string.Format(@"select Id,Title,Testers,StartTime,EndTime from(
SELECT ROW_NUMBER() over(order by Id desc) rowNum,Id,Title,Testers,StartTime,EndTime
  FROM ExamType
  ) t where rowNum between {0} and {1};",sNum, eNum);
            string strSql2 = string.Format(@"select COUNT(0) from ExamType;");
            var list = ctx.ExecuteQuery<ExamType>(strSql);
            rptList.DataSource = list;
            rptList.DataBind();

            var list2 = ctx.ExecuteQuery<int>(strSql2);
            Model.TotalCount = list2.First();
        }
    }
}